$(function(){
    var obj = {
        account: '',
        ajaxStatus: false,
        user: {},
        init: function () {
            var that = this;
            that.account = localStorage.getItem('myTel') || '';
            $.initNavBar(2);
            that.addEvent();
            that.initUserMsg();
        },
        addEvent: function () {
            var that = this;
            // 登录
            $('#userLogo,#visitor').click(function () {
                $.authIsLogin()
            });
            // 登出
            $('#exit').click(function () {
                localStorage.clear();
                $(this).hide();
                $.alert('已退出登录');
                that.initUserMsg();
            });
            //修改用户信息
            $('#register').click(function () {
                location.href = './mobileRegister.html';
            });
            // 我的信息
            $('#myInformation').click(function () {
                location.href = './mobileRegister.html?type=edit';
            });
            // 申请记录
            $('#myApply').click(function () {
                location.href = './myApplyLog.html';
            })
        },
        initUserMsg: function () {
            var that = this;
            $(this).hide();
            if($.authIsLogin(true)){
                // 登录
                var userName = that.account.slice(0,3)+'****'+that.account.slice(-4);
                $('#userName').html(userName);
                $('#userLogo').removeClass('default');
                $('#userMsg').removeClass('none');
                $('#visitor').addClass('none');
                that.ajaxGetUserMsg();
            }else{
                $('#myInformation').hide();
                $('#myApply').hide();
                $('#exit').hide();
                $('#userName').html('');
                $('#userLogo').addClass('default');
                $('#userMsg').addClass('none');
                $('#visitor').removeClass('none');
            }
        },
        // 获取用户信息
        ajaxGetUserMsg: function() {
            var that = this;
            $.getData({
                url: $.getAjaxHost('def') + 'cxjy/zpinfo/getUserMsg',
                type: 'get',
                contentType: 'application/json',
                data: {
                    account:encodeURI(that.account),
                },
                success: function (res) {
                    that.user = res.data;
                    if(that.user&&that.user.jobType){
                        $('#jobWant').html(that.user.jobType+'&nbsp;|&nbsp;'+that.user.hy)
                    }
                    if(that.user.sex == '女') $('#userLogo').addClass('women');
                    else $('#userLogo').removeClass('women');

                },
                error: function (res) {
                }
            })
        }
    };
    obj.init();
});